<#assign pageName="系统用户管理">
<#function getUserDepName userId>
    <#assign userDepName="">
    <#list userDepList as dataItem>
        <#if dataItem.user_id == userId>
            <#assign userDepName += "<div>${dataItem.dep_name}</div>">
        </#if>
    </#list>
    <#return userDepName>
</#function>
<#function getUserRoleName userId>
    <#assign userRoleName="">
    <#list userRoleList as dataItem>
        <#if dataItem.user_id == userId>
            <#assign userRoleName += "<div>${dataItem.role_name}</div>">
        </#if>
    </#list>
    <#return userRoleName>
</#function>
<#function getUserAccount userId>
    <#assign userAccount="">
    <#list userAccountList as dataItem>
        <#if dataItem.userId == userId>
            <#assign userAccount += "<div>${dataItem.loginType} : ${dataItem.loginAccount}</div>">
        </#if>
    </#list>
    <#return userAccount>
</#function>
<@override name="page-content">
    <form class="layui-form form-horizontal" role="form" method="post">
        <div class="layui-form-search panel">
            <input type="text" hidden="hidden" name="_STATE"/>
            <@ctrl.TreeSelectQuery path="users.guid" dataList=guidsList![] fieldText="sysModuleName"
                fieldValue="guid" labelText="所属平台" fieldParentID="upperGuid" parentidValue="${(guids.upperGuid)!'-1'}">
              </@ctrl.TreeSelectQuery>  
             <@ctrl.TreeSelectQuery path="users.depId" dataList=depList fieldText="depName" 
                fieldValue="depId" labelText="所属机构" fieldParentID="upperId" parentidValue="${(dep.upperId)!'-1'}">
                   <option value="">—请选择所属机构—</option>
              </@ctrl.TreeSelectQuery>
             <@ctrl.SingleSelectQuery path="users.roleId" options=roleList![] text="roleName" value="roleId" labelText="所属角色">
                 <option value="">—请选择所属角色—</option>
             </@ctrl.SingleSelectQuery>
             <@ctrl.TextboxQuery path="users.loginAccount" labelText="用户账号"/>
             <@ctrl.TextboxQuery path="users.uname" labelText="用户名称"/>
             <div class="margin-5">
                 <a href="javascript:;" onclick="$('form:first').submit();" class="layui-btn layui-btn-sm">
                     <i class="layui-icon layui-icon-search"></i>查询
                 </a>
                 <a href="javascript:;" class="layui-btn layui-btn-warm layui-btn-sm js-reset">
                    <i class="layui-icon layui-icon-refresh-1"></i>重置
                 </a>
                 <a href="add" class="layui-btn layui-btn-normal layui-btn-sm">
                     <i class="layui-icon layui-icon-add-1"></i>新增
                 </a>
             </div>
        </div>
        <table class="layui-table">
            <thead>
                <tr>
                     <th class="align-center" width="50px" nowrap="nowrap">序号</th>
                     <th class="align-center" nowrap="nowrap">用户名称</th>
                     <th class="align-center" nowrap="nowrap">用户账号</th>
                     <th class="align-center layui-hide-xs" nowrap="nowrap">所属机构</th>
                     <th class="align-center layui-hide-xs">所属角色</th>
                     <th class="align-center">创建时间</th>
                     <th class="align-center">状态</th>
                     <th class="align-center" width="150px">操作</th>
                 </tr>
             </thead>
             <tbody>
                 <#if (queryResult.rows)?has_content>
                     <#list queryResult.rows as dataItem>  
                     <tr>
                         <td class="align-center" width="50px" nowrap="nowrap">
                             ${(pageNo-1)*pageSize+dataItem_index+1}
                         </td>
                         <td class="align-center" nowrap="nowrap">
                             ${dataItem.uname}
                         </td>
                         <td class="align-center" nowrap="nowrap">
                             ${getUserAccount(dataItem.userId)}
                         </td>
                         <td class="layui-hide-xs" nowrap="nowrap">
                             ${getUserDepName(dataItem.userId)}
                         </td>
                         <td class="layui-hide-xs">
                             ${getUserRoleName(dataItem.userId)}
                         </td>
                         <td class="align-center">
                             <span>${(dataItem.indate)?date}</span>
                         </td>
                         <td class="align-center" nowrap="nowrap">
                             <#if dataItem.enable?string == "T">
                                 <span class="layui-bg-green status-show">启用</span>
                             <#else>
                                 <span class="layui-bg-red status-show">禁用</span>
                             </#if>
                         </td>
                         <td class="align-center">
                             <div class="layui-table-cell">
                                 <#if dataItem.enable == "T">
                                     <a class="layui-btn layui-btn-normal layui-btn-xs" href="edit/${dataItem.userId}">
                                          <i class="layui-icon layui-icon-edit"></i>编辑
                                     </a> 
                                     <a class="layui-btn layui-btn-warm layui-btn-xs" href="auth/${dataItem.userId}" >
                                         <i class="layui-icon layui-icon-auz"></i>授权
                                     </a>
                                     <button type="button" class="layui-btn layui-btn-danger layui-btn-xs js-disableusr"
                                         data-id="${dataItem.userId}" data-name="${dataItem.uname}">
                                         <i class="layui-icon layui-icon-util"></i>禁用
                                     </button>
                                     <button type="button" class="layui-btn layui-btn-danger layui-btn-xs js-clrpwd" 
                                         data-id="${dataItem.userId}" data-name="${dataItem.uname}" >
                                         <i class="layui-icon layui-icon-password"></i>还原
                                     </button>
                                 <#else>
                                     <button type="button" class="layui-btn layui-btn-blue layui-btn-xs js-enableusr"
                                         data-id="${dataItem.userId}" data-name="${dataItem.uname}" >
                                         <i class="layui-icon layui-icon-util"></i>启用
                                     </button>
                                 </#if>
                                 <button type="button" class="layui-btn layui-btn-danger layui-btn-xs js-delusr"
                                      data-id="${dataItem.userId}" data-name="${dataItem.uname}">
                                      <i class="layui-icon layui-icon-delete"></i>销号
                                  </button>
                             </div>
                         </td>
                     </tr>
                     </#list>
                 <#else>
                     <tr>
                         <td colspan="8" style="color:red;text-align:center;font-weight:bold;">暂无符合条件的用户信息</td>
                     </tr>
                 </#if>    
                 </tbody>
             </table>
             <@ctrl.pageShow (queryResult.total)!0, (queryResult.pageIndex)!0 />
        </div>
    </form>
</@override>
<@override name="page-scripts">
    <script>
        $(function(){
            layui.use(['form','layer', 'jquery'], function(){
                var form=layui.form;
                var layer=layui.layer;
                var $ = layui.jquery;
                $('.js-reset').on('click', function(){
                    $('#pageNo').val(1);
                    $('#depId').val("");
                    $('#roleId').val("");
                    $('#loginAccount').val("");
                    $('#uname').val("");
                    $('form:first').submit();
                });
                //平台机构角色联动
                form.on('select(guid)', function(data){
                    var guid = data.value;
                    $.post('${rc.getContextPath()}/admin/department/queryall', {'guid': guid}, function(data){
                        var $html = "<option value=''>－请选择所属机构－</option>"
                        $.each(data, function(index, item){
                            $html += "<option value='" + item.depId + "'>" + item.depName + "</option>";
                        })
                        $("#depId").html($html);
                        form.render("select");
                    })
                });
                form.on('select(depId)', function(data){
                    var guid = $('#guid').val();
                    var depId = data.value;
                    $.post('${rc.getContextPath()}/admin/roles/queryall', {'guid':guid,'depId':depId}, function(data){
                        var $html = "<option value=''>－请选择所属角色－</option>"
                        $.each(data, function(index, item){
                            $html += "<option value='" + item.roleId + "'>" + item.roleName + "</option>";
                        })
                        $("#roleId").html($html);
                        form.render("select");
                    })
                });
                
                /* 用户禁用 */
                $('.js-disableusr').on('click',function(){
                    var userId = $(this).attr("data-id");
                    var userName = $(this).attr("data-name");
                    confirmSubmit('禁用账号后用户将拒绝登录，确定要禁用用户‘'+userName+'’的账号吗？', {'userId':userId},'disable')
                });
                /* 用户启用 */
                $('.js-enableusr').on('click',function(){
                    var userId = $(this).attr("data-id");
                    var userName = $(this).attr("data-name");
                    confirmSubmit('确定要启用用户‘'+userName+'’的账号吗？', {'userId':userId}, 'enable')
                });
                /* 账号删除 */
                $('.js-delusr').on('click',function(){
                    var userId = $(this).attr("data-id");
                    var userName = $(this).attr("data-name");
                    confirmSubmit('账号注销后，保存到平台的数据将会被删除并将无法恢复,确定要注销用户‘'+userName+'’的账号吗？', {'userId':userId}, 'del')
                })
                /* 密码还原 */
                $('.js-clrpwd').on('click',function(){
                    var userId = $(this).attr("data-id");
                    var userName = $(this).attr("data-name");
                    confirmSubmit('确定要还原用户‘'+userName+'’的账号密码？', {'userId':userId}, 'clrpwd')
                })
            })
        })
    </script>
</@override>
<@extends name="/layout/basepage.html"/>